<?php

namespace app\common\model;

use think\Db;
use think\Model;

/**
 * 任务维修明细
 */
class TasksService extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'images_text',
    ];

    //图片数组
    public function getImagesTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['images']) ? $data['images'] : '');
        if (!$value){
            return [];
        }
        $arr = explode(',',$value);
        foreach ($arr as &$item){
            $item = cdnurl($item,true);
        }
        return $arr;
    }

    //指定用户指定任务的记录
    public static function getTaksLogs($user_id,$task_id)
    {
        return self::where('user_id',$user_id)->where('task_id',$task_id)->where(['total_fee'=>['>',0]])->order('createtime desc')->select();
    }

}
